package com.example.demo.controller;

import com.example.demo.bean.User;
import com.example.demo.service.UserService;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("user")
public class UserController {

    @Resource
    private UserService userService;

    @RequestMapping("/getUser")
    @ResponseBody
    public User getUserById(HttpServletRequest request, Model model){
        int id = Integer.parseInt(request.getParameter("id"));
        User user = this.userService.getUserById(id);
        return user;
    }

    @RequestMapping("/insertUser")
    @ResponseBody
    public int insertUser(@ModelAttribute User user){
        int i = userService.insertUser(user);
        return i;
    }
}
